﻿ #pragma once
#define LK_
#include<typeinfo>
#include <iostream>
#include <time.h>
#include <cmath>
#include<vector>
namespace LK
{
	//基类
	struct Object;
	//封箱类
	struct MObjects;
	//引用计数类
	//struct RefCount;
	//字符串
	struct String;
	//异常类型
	struct Exception;
	//类型信息类
	struct Type;
	//随机数生成器
	struct Random;
	//时间
	struct Time;
	//浅表复制接口
	struct ICloneables;

	//空指针异常的智能指针类型
	struct PointerIsNullException ;
	//内存耗尽异常的智能指针类型
	struct POutOfMemoryException;
	//指针失效异常的智能指针类型
	struct PPointerFailureException;
	//未支持异常的智能指针类型
	struct PNotSupportException;
	//空指针异常的智能指针类型
	struct PPointerIsNullException ;
	//未支持异常的智能指针类型
	struct PNotSupportException;

	//智能指针模板
	template<class T>struct ptr;
	//P开头表示智能指针
	typedef ptr<Object> PObject;
	typedef ptr<Exception> PException;
	typedef ptr<MObjects> PMObjects;
	typedef ptr<String> PString;
	typedef ptr<Type> PType;
	typedef ptr<Random> PRandom;

	//成员T表示智能指针所指向的类型
	template<class TT>struct TypeOfReference;
	template<class TT>struct TypeOfReference<ptr<TT> >{typedef TT T;};


#ifdef SUPPORT_VARIADIC_TEMPLATES
	//抛出异常的提前声明
	template<class T, class ...Args>inline void Throw(Args ...t);
	template<class ReturnType,class T, class ...Args>inline ReturnType RThrow(Args ...t);
#else
	//抛出异常的提前声明
#define TMPF(x) template<MF4_RepeatAsc_(class T,,0,x)>inline void Throw(MF4_RepeatAsc_(T, , 1, x));\
	template<class RT,MF4_RepeatAsc_(class T,,0,x)>inline RT RThrow(MF4_RepeatAsc_(T, , 1, x));
	MF3_RepeatAsc(TMPF, 0, 16);
#undef TMPF
#endif
	//动态转换基类指针到派生类，不做检查
	template<class T, class BT>inline T* CastPointer(BT const* p);
	//静态转换派生类指针到基类，不做检查
	template<class T>inline Object* StaticCastPointer(T const* p);
	//检查指针，如果指针为NULL，则抛出异常
	template<class T, class BT>inline T* CheckPointer(BT const* p);
	//一个大小为size的结构体，size>0
	template<const int size>struct StructOfSize { unsigned char tmp[size]; };

	//类型重命名
	typedef unsigned long long u64;
	typedef unsigned long u32;
	typedef unsigned int ui32;
	typedef unsigned short u16;
	typedef unsigned char u8;
	typedef long long s64;
	typedef long s32;
	typedef int i32;
	typedef short s16;
	typedef signed char s8;

	typedef const unsigned long long cu64;
	typedef const unsigned long cu32;
	typedef const unsigned int cui32;
	typedef const unsigned short cu16;
	typedef const unsigned char  cu8;
	typedef const long long cs64;
	typedef const int ci32;
	typedef const long cs32;
	typedef const short cs16;
	typedef const signed char cs8;

#if _X64 == 1
	typedef long long index_t;
#else
	typedef int index_t;
#endif
#ifndef _WINDOWS
	typedef unsigned char BYTE;
	typedef unsigned short WORD;
	typedef unsigned long DWORD;
	typedef long HRESULT;
	typedef const wchar_t* LPCWSTR;
	typedef wchar_t* LPWSTR;
	typedef wchar_t WCHAR;
	typedef char CHAR;
	typedef const char* LPCSTR;
	typedef char* LPSTR;
	typedef void* PVOID;
#endif
	//右值引用符号
#ifdef SUPPORT_RIGHT_VALUE_REFERENCE
#define __RVR &&
#else
#define __RVR
#endif
	/**
	@breif 自定义null，用以取代NULL*/
	static struct null_t {
		template<class T>operator T*()const { return NULL; }
		template<class T, class C>operator T C::*()const { return NULL; }
		template<class T>bool operator==(T*p)const { return !p; }
		template<class T>bool operator!=(T*p)const { return p!=NULL; }
		template<class T>friend bool operator==(T*p,null_t) { return !p; }
		template<class T>friend bool operator!=(T*p,null_t) { return p!=NULL; }
		bool operator!()const { return true; }
	private:
		void operator=(null_t const&);
	}null;
#define null null
	namespace Collection {
		/**
		@brief 表示一个数组接口*/
		template<class T>struct IArray;
		/**
		@brief 数组迭代器*/
		template<class T>struct ArrayIterator;
	}
	typedef ptr<Collection::IArray<u8>> PByteArray;
	typedef ptr<Collection::IArray<u64>> PULLArray;
	typedef ptr<Collection::IArray<wchar_t>> PWCharArray;
	typedef ptr<Collection::IArray<char>> PCharArray;
	typedef ptr<Collection::IArray<PString>> PStringArray;
}


